package cn.stylefeng.guns.modular.productfunction.controller;

import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.productfunction.entity.ShiCalfFunction;
import cn.stylefeng.guns.modular.productfunction.entity.ShiWhether;
import cn.stylefeng.guns.modular.productfunction.model.params.ShiCalfFunctionParam;
import cn.stylefeng.guns.modular.productfunction.service.ShiCalfFunctionService;
import cn.stylefeng.guns.modular.productfunction.service.ShiWhetherService;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

import static cn.stylefeng.roses.core.reqres.response.ResponseData.DEFAULT_SUCCESS_CODE;


/**
 * 控制器
 *  小腿功能表
 * @author 石博士
 * @Date 2019-07-05 14:38:36
 */
@Controller
@RequestMapping("/shiCalfFunction")
public class ShiCalfFunctionController extends BaseController {

    private String PREFIX = "/Shiproductfunction/shiCalfFunction";

    @Autowired
    private ShiCalfFunctionService shiCalfFunctionService;

    @Autowired
    private ShiWhetherService shiWhetherService;

    /**
     * 跳转到主页面
     *
     * @author 石博士
     * @Date 2019-07-05
     */
    @RequestMapping("/index")
    public String index() {
        return PREFIX + "/shiCalfFunction.html";
    }

    /**
     * 新增页面
     *
     * @author 石博士
     * @Date 2019-07-05
     */
    @RequestMapping("/add")
    public String add(Model model) {
        List<ShiWhether> shiWhetherList = shiWhetherService.findListBySpec(null);
        model.addAttribute("shiWhetherList", shiWhetherList);
        return PREFIX + "/shiCalfFunction_add.html";
    }

    /**
     * 编辑页面
     *
     * @author 石博士
     * @Date 2019-07-05
     */
    @RequestMapping("/edit")
    public String edit() {
        return PREFIX + "/shiCalfFunction_edit.html";
    }

    /**
     * 新增接口
     *
     * @author 石博士
     * @Date 2019-07-05
     */
    @RequestMapping("/addItem")
    @ResponseBody
    public ResponseData addItem(ShiCalfFunctionParam shiCalfFunctionParam) {
        ShiCalfFunction shiCalfFunction = this.shiCalfFunctionService.add(shiCalfFunctionParam);
        return new ResponseData(true, DEFAULT_SUCCESS_CODE, "请求成功", shiCalfFunction);
    }

    /**
     * 编辑接口
     *
     * @author 石博士
     * @Date 2019-07-05
     */
    @RequestMapping("/editItem")
    @ResponseBody
    public ResponseData editItem(ShiCalfFunctionParam shiCalfFunctionParam) {
        this.shiCalfFunctionService.update(shiCalfFunctionParam);
        return ResponseData.success();
    }

    /**
     * 删除接口
     *
     * @author 石博士
     * @Date 2019-07-05
     */
    @RequestMapping("/delete")
    @ResponseBody
    public ResponseData delete(ShiCalfFunctionParam shiCalfFunctionParam) {
        this.shiCalfFunctionService.delete(shiCalfFunctionParam);
        return ResponseData.success();
    }

    /**
     * 查看详情接口
     *
     * @author 石博士
     * @Date 2019-07-05
     */
    @RequestMapping("/detail")
    @ResponseBody
    public ResponseData detail(ShiCalfFunctionParam shiCalfFunctionParam) {
        ShiCalfFunction detail = this.shiCalfFunctionService.getById(shiCalfFunctionParam.getId());
        return ResponseData.success(detail);
    }

    /**
     * 查询列表
     *
     * @author 石博士
     * @Date 2019-07-05
     */
    @ResponseBody
    @RequestMapping("/list")
    public LayuiPageInfo list(ShiCalfFunctionParam shiCalfFunctionParam) {
        return this.shiCalfFunctionService.findPageBySpec(shiCalfFunctionParam);
    }

}


